<template>
  <el-dialog :visible.sync="visible" v-dialogDrag :title="title" :close-on-click-modal="false" class="tl-dialog" width="1200px" @open="open" @close="close" :append-to-body="true">
    <el-form class="tl-form" ref="form" :model="model" :rules="rules" label-width="150px" :disabled="disableEditSubmit">
      <el-row>
        <el-col :span="24">
          <el-form-item label="项目编号" prop="projectcode" :rules="rules.validateRequire">
            <el-input v-model="model.projectcode" type="textarea" :rows="4" placeholder="多个项目编号请使用英文逗号分割"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="春季/秋季攻势" prop="projectattack">
            <el-select v-model="model.projectattack" filterable clearable>
              <el-option v-for="item in projectattackList" :key="item.code" :label="item.name" :value="item.code" />
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="doSubmitEdit" :loading="saveLoading" v-if="disableEditSubmit === false">确认</el-button>
    </div>
  </el-dialog>
</template>

<script>
/** mixins */
import { mixin_edit } from '@tapui/mixins/mixin_edit'
/** 子组件 */
/** 工具类 */
import { putAction, getAction, postAction, deleteAction } from '@tapui/utils/http'
/** VUE配置 */
export default {
  mixins: [mixin_edit],
  components: {},
  data() {
    return {
      moduleTitle: '春季/秋季攻势历史数据处理',
      urlPrefix: '/mpm/project/',
      url: {
        // 额外的url
        addProjectAttackFirst: '/mpm/project/addProjectAttackFirst'
      }
    }
  },
  computed: {
    projectattackList() {
      if (this.codeModel.hasOwnProperty('projectattackList')) {
        return this.codeModel.projectattackList.slice(0, 2)
      } else {
        return []
      }
    }
  },
  methods: {
    doSubmitEdit() {
      this.saveLoading = true
      putAction(this.url.addProjectAttackFirst, this.model).then((res) => {
        if (res.success) {
          this.$tap.message('修改成功', 'success')
          this.visible = false
          this.$emit('refresh')
        } else {
          this.$tap.alert('修改失败，请联系管理员', 'warning')
        }
        this.saveLoading = false
      })
    }
  }
}
</script>
